<?php
/**
 * Created by PhpStorm.
 * User: fengbob
 * Date: 2018/3/4
 * Time: 20:45
 */

use yii\helpers\Url;

$web = \yii\helpers\Url::base();
$url = \app\librarys\Tools::urlBase();
?>

<link rel="stylesheet" type="text/css" href="<?= $web ?>/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="<?= $web ?>/css/font-awesome.css">
<link rel="stylesheet" type="text/css" href="<?= $web ?>/css/frame.css">
<link rel="stylesheet" type="text/css" href="<?= $web ?>/css/tree-autocomplete.css">
<link rel="stylesheet" type="text/css" href="<?= $web ?>/css/jquery.Jcrop.css">

<!--[if IE]>
<link rel="stylesheet" type="text/css" href="<?= $web ?>/css/ie.css"/>
<![endif]-->

<style type="text/css">
    #errorModal {
        z-index: 1099;
    }

    #infoModal {
        z-index: 1098;
    }

    #confirmModal {
        z-index: 1097;
    }
</style>

<script type="text/javascript" src="<?= $web ?>/js/jquery-1.11.3.js"></script>
<script type="text/javascript" src="<?= $web ?>/js/jquery.cookie.js"></script>
<script type="text/javascript" src="<?= $web ?>/js/bootstrap.js"></script>
<script type="text/javascript" src="<?= $web ?>/js/frame.js"></script>
<script type="text/javascript" src="<?= $web ?>/js/tools.js"></script>
<script type="text/javascript" src="<?= $web ?>/js/tree-autocomplete.js"></script>
<script type="text/javascript" src="<?= $web ?>/js/tree-autocomplete-pager.js"></script>
<script type="text/javascript" src="<?= $web ?>/js/bootstrap-datetimepicker.js"></script>
<script type="text/javascript" src="<?= $web ?>/js/bootstrap-datetimepicker.zh-CN.js"></script>
<script type="text/javascript" src="<?= $web ?>/js/validate.js"></script>
<script type="text/javascript" src="<?= $web ?>/js/jcrop/jquery.Jcrop.js"></script>
<div class="panel panel-frame">
    <div class="table-responsive">
        <form action ="category-goods-save-handler" method="post">
            <input hidden="true" id="category_id" name="category_id" value="<?=$category_id?>"/>
        <table class="table table-bordered table-hover" id="goods_category_form">
            <thead>
            <tr>
                <th>选择</th>
                <th>商品名称</th>
                <th>商品图片</th>
                <th>现有分类</th>
            </tr>
            </thead>
            <tbody>
            <?php
            for ($i = 0; $i < count($goods_items); $i++) {
                $item = $goods_items[$i];
                ?>
                <tr>
                    <td><input type="checkbox" value="<?=$item['id']?>" name="check[]"/> </td>
                    <td><?= $item['name'] ?></td>
                    <td class="td-img">
                        <?php if (!empty($item['small_image_url'])) {
                            ?>
                            <img src="<?=\app\models\File::getFile($item['small_image_url'])['url'] ?>"  class="img-small" style="height: 50px;">
                            <?php
                        }
                        ?></td>
                    <td><?php
                        $names = '';
                        foreach ($item['categories'] as $ca){
                                $names = $names.' '.$ca['name'];
                        } ?>
                    <?=$names?>
                </tr>
                <?php
            }
            ?>
            </tbody>
        </table>
            <input type="submit" />
        </form>
    </div>
<!--    <div class="button-container"><a class="btn btn-link" href="javascript:save()">保存</a> </div>-->
    <div class="table-pagination">
        <?= \app\widgets\LinkPagerExt::widget(['pagination' => $pagination]) ?>
    </div>
</div>





<script type="text/javascript">

    function search() {
        var name = $("#name").val();
        var href = window.location.href;
        var index = href.indexOf("?page=");
        if (index > 0) {
            href = href.substr(0, index);
        }
        var href_str = href + "?page=1";

        if (name != '' && name != null) {
            href_str = href_str + "&name=" + name;
        }
        window.location.href = href_str;
    }

    function editData(id) {

        $('#dataModalEdit').modal({
            keyboard: false, backdrop: 'static', show: false
        });

        $("#dataModalEdit").modal('show');
        $("#dataModalEdit").on('show');
        var data = {};
        if (id != undefined) {
            data.id = id;
        }

        $("#dataModalEdit").find("#modalEdit").html('正在加载数据...');

        requestHtml('order-partial', data, true, function (responseHtml) {
            $("#dataModalEdit").find("#modalEdit").html(responseHtml);
        });
    }

    function save() {
//        debugger;
        var data={};
        data.check= $("#goods_category_form").find("#check");
        alert(data);


        requestJson("category-goods-save-handler", data, true, function (response) {
            alert(response);
            if (response.status == 0) {
//                search();
            }
            else {
                errorDialog(response.message);
            }
        })
    }

    function deleteData(id) {
        confirmDialog(id, null, function (id) {
            var data = {};
            data.id = id;
            requestJson("mini-program-delete-handler", data, true, function (response) {
                if (response.status == 0) {
                    search();
                } else {
                    errorDialog(response.message);
                }
            });
        });
    }

</script>
